package com.yjd.pub.repayment.service;

import com.yjd.comm.base.dao.IBaseDao;
import com.yjd.comm.base.enums.DbWREnums;
import com.yjd.comm.base.service.impl.BaseServiceImpl;
import com.yjd.comm.repayment.model.RepaymentClearModel;
import com.yjd.comm.repayment.service.IRepaymentClearService;
import com.yjd.comm.util.FrameUtil;
import com.yjd.pub.repayment.dao.IRepaymentClearDao;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <b>description</b>：还款(vip商户)清算表业务实现<br>
 * <b>time</b>：2017-10-19 15:51:31 <br>
 * <b>author</b>：  carl
 */
@Service("repaymentClearService")
public class RepaymentClearServiceImpl extends BaseServiceImpl implements IRepaymentClearService {

	/**
	 * 插入
	 * 
	 * @param model
	 * @return
	 * @throws Exception
	 */
	public RepaymentClearModel insert(RepaymentClearModel model) throws Exception {
		return this.repaymentClearDao.insertModel(model, true);
	}

	/**
	 * 更新
	 * 
	 * @param model
	 * @return
	 * @throws Exception
	 */
	public int update(RepaymentClearModel model) throws Exception {
		return this.repaymentClearDao.updateModel(model, true);
	}

	/**
	 * 根据id删除
	 * 
	 * @param id
	 * @return
	 * @throws Exception
	 */
	public int delete(long id) throws Exception {
		Map<Object, Object> paramMap = new HashMap<Object, Object>();
		paramMap.put("id", id);
		return this.repaymentClearDao.deleteModel(paramMap, true);
	}

	@Override
	public List queryRepaymentInfo(Map paramMap, DbWREnums write) throws Exception {
		return this.repaymentClearDao.queryRepaymentInfo(paramMap, write.isWrite());
	}


	@Override
	public Double querySumRepaymentPrice(Long startTime, Long endTime) throws Exception {
		if(startTime==null||endTime==null){
			FrameUtil.throwBaseException1("请求参数不能为空");
		}
		return this.repaymentClearDao.querySumRepaymentPrice(FrameUtil.newHashMap("startTime",startTime,"endTime",endTime));
	}

	@Override
	public Double querySumPfProfit(Long startTime, Long endTime) throws Exception {
		if(startTime==null||endTime==null){
			FrameUtil.throwBaseException1("请求参数不能为空");
		}
		return this.repaymentClearDao.querySumPfProfit(FrameUtil.newHashMap("startTime",startTime,"endTime",endTime));
	}

	@Resource
	private IRepaymentClearDao repaymentClearDao;

	@Override
	public IBaseDao getBaseDao() {
		return this.repaymentClearDao;
	}

}
